package com.lagou.edu.kubernetes.common;

import com.lagou.edu.kubernetes.exception.BusinessException;
import org.springframework.web.bind.annotation.*;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handleException(Exception ex) {
        WebResult result = new WebResult();
        result.setOperCode(500);
        result.setOperMsg(ex.getMessage());
        return result;
    }

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public Object handleBusinessException(BusinessException ex) {
        WebResult result = new WebResult();
        result.setOperCode(ex.getCode());
        result.setOperMsg(ex.getMsg());
        return result;
    }
}
